package com.wss.service.impl;

import com.wss.dao.OrderDao;
import com.wss.domain.Message;
import com.wss.domain.Order;
import com.wss.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public List<Order> findOrderAll() {
        System.out.println("业务层：查询所有订单");
        return orderDao.findOrderAll();
    }

    @Override
    public List<Order> findOrderByUid(int uid) {
        System.out.println("业务层：查询该用户订单");
        return orderDao.findOrderByUid(uid);
    }

    @Override
    public Order findOrderByUidnVid(Order order) {
        System.out.println("业务层：查询该用户是否购买此课程订单");
        return orderDao.findOrderByUidnVid(order);
    }

    @Override
    public Message addOrder(Order order) {
        System.out.println("业务层：添加订单");
        Message message = new Message();
        int res = orderDao.addOrder(order);
        if (res > 0){
            message.setResCode(1);
            message.setResultMsg("购买成功");
        }else{
            message.setResCode(0);
            message.setResultMsg("购买失败");
        }
        return message;
    }

    @Override
    public void changeOrder(Order order) {
        System.out.println("业务层：修改订单");
        orderDao.changeOrder(order);
    }

    @Override
    public Message deleteOrder(Order order) {
        System.out.println("业务层：删除订单");
        Message message = new Message();
        int res = orderDao.deleteOrder(order);
        if (res > 0){
            message.setResCode(1);
            message.setResultMsg("删除成功");
        }else{
            message.setResCode(0);
            message.setResultMsg("删除失败");
        }
        return message;
    }

}
